<?php
 
defined('DSVH') or die('Restricted access');
 
//add chuc danh
function insertthietkeweb($local){
    mysql_query("insert thiet_ke_web set 
    tieu_de = '".$local['tieu_de']."',
    avatar = '".$local['avatar']."',
    status = '".$local['status']."',
    cat_id = '".$local['cat_id']."',
    mo_ta_chung = '".$local['mo_ta_chung']."',
    mo_ta_chi_tiet = '".$local['mo_ta_chi_tiet']."',
    user_id = '".$_SESSION['can_bo_id']."',
    add_date = NOW(),
    tag = '".$local['tag']."',
    last_edit = NOW(),
    last_user_edit = '".$_SESSION['can_bo_id']."'",
    dbconnect());
}

function insertloaithietkeweb($local){
    mysql_query("insert loai_thiet_ke_web set
    ten = '".$local['ten']."',
    user_id = '".$_SESSION['user_id']."',
    sap_xep = '".$local['sap_xep']."',
    rang_buoc = '".$local['rang_buoc']."',
    add_date = NOW()",
    dbconnect());
}

function editloaithietkeweb($id, $local)
{
    mysql_query("update loai_thiet_ke_web set 
    ten = '".$local['ten']."',
    user_id = '".$_SESSION['can_bo_id']."',
    sap_xep = '".$local['sap_xep']."',
    rang_buoc = '".$local['rang_buoc']."'
    where id = '".(int)$id."'", dbconnect());
}

function rangbuoc($id, $status)
{
    mysql_query("update loai_thiet_ke_web set 
    rang_buoc = '".$status."'
    where id = '".(int)$id."'", dbconnect());
}
//list chuc danh
function getListthietkeweb($start, $limit)
    {
        $local_list = mysql_query("SELECT * FROM thiet_ke_web
        left join loai_thiet_ke_web  ON thiet_ke_web.cat_id = loai_thiet_ke_web.id
        order by thiet_ke_web_id desc LIMIT ".(int)$start.",".(int)$limit."", dbconnect());
        $result = array();
        while ($local = mysql_fetch_array($local_list)){
            $result []= $local;
        }
        return $result;
    }
    
function getListthietkewebtheoloai($id, $start, $limit)
    {
        $local_list = mysql_query("SELECT * FROM thiet_ke_web
        left join loai_thiet_ke_web  ON thiet_ke_web.cat_id = loai_thiet_ke_web.id
    where loai_thiet_ke_web.id = '".$id."'
        order by thiet_ke_web_id desc LIMIT ".(int)$start.",".(int)$limit."", dbconnect());
        $result = array();
        while ($local = mysql_fetch_array($local_list)){
            $result []= $local;
        }
        return $result;
    }

function getListloaithietkeweb($start, $limit)
    {
        $local_list = mysql_query("SELECT * FROM loai_thiet_ke_web
        order by id desc LIMIT ".(int)$start.",".(int)$limit."", dbconnect());
        $result = array();
        while ($local = mysql_fetch_array($local_list)){
            $result []= $local;
        }
        return $result;
    }
    
//ham lay du lieu phong ban theo id
function getthietkeweb($id)
    {
    $pro = mysql_query("select * from thiet_ke_web where thiet_ke_web_id = '".(int)$id."'", dbconnect());
    return mysql_fetch_array($pro);
    }
    
function getloaithietkeweb($id)
    {
    $pro = mysql_query("select * from loai_thiet_ke_web where id = '".(int)$id."'", dbconnect());
    return mysql_fetch_array($pro);
    }
    
//cap nhat trong muc sua
function editthietkeweb($id, $local)
{
    mysql_query("update thiet_ke_web set
    tieu_de = '".$local['tieu_de']."',
    avatar = '".$local['avatar']."',
    status = '".$local['status']."',
    cat_id = '".$local['cat_id']."',
    mo_ta_chung = '".$local['mo_ta_chung']."',
    mo_ta_chi_tiet = '".$local['mo_ta_chi_tiet']."',
    add_date = NOW(),
    tag = '".$local['tag']."',
    last_edit = NOW(),
    last_user_edit = '".$_SESSION['can_bo_id']."'
    where thiet_ke_web_id = '".(int)$id."'", dbconnect());
}

// xoa thu muc
function delthietkeweb($id){
    mysql_query("delete from thiet_ke_web where thiet_ke_web_id ='".(int)$id."'", dbconnect());
}

function total(){
   $result = mysql_query("select * from thiet_ke_web",dbconnect());
    return mysql_num_rows($result);
}

function totalloaithietkeweb(){
   $result = mysql_query("select * from loai_thiet_ke_web",dbconnect());
    return mysql_num_rows($result);
}

 function checkcanbo($param){
    $sql = "SELECT * FROM can_bo where thiet_ke_web_id = '".escape($param)."'";
    $result = mysql_query($sql, dbconnect());
    return mysql_num_rows($result);
}

function check_hoso_pvt($param){
    $sql = "SELECT * FROM ho_so_phi_vat_the where thiet_ke_web_id = '".escape($param)."'";
    $result = mysql_query($sql, dbconnect());
    return mysql_num_rows($result);
}



?>